package com.aletto.general_store.presenters;

import com.aletto.general_store.GeneralStoreApplication;
import com.aletto.general_store.data.DataRepository;
import com.aletto.general_store.presenters.core.SimpleTemplate;
import com.aletto.general_store.ui.adapters.ConsumerOrderAdapter;
import com.aletto.general_store.utils.ToastUtils;
import com.sisyphus.spinach.core.INetTask;
import com.sisyphus.spinach.network.presenters.NetSingleTask;
import com.sisyphus.spinach.network.views.ToastView;

import java.util.function.Consumer;

public class ConsumerOrderConfirmTask extends SimpleTemplate<Object> {

    private final Long orderId;

    private final Consumer<Object> consumer;


    public ConsumerOrderConfirmTask(Long orderId, Consumer<Object> consumer) {
        this.orderId = orderId;
        this.consumer = consumer;
    }

    @Override
    public INetTask.View<Object> view() {
        return new ToastView<>(GeneralStoreApplication.sInstance){
            @Override
            public void success(Object data) {
                consumer.accept(data);
            }
        };
    }

    @Override
    public INetTask.Presenter<Object, INetTask.View<Object>> presenter() {
        return new NetSingleTask<>(DataRepository.getInstance().confirmReceipt(orderId));
    }
}
